package com.linhui.consumer;

import com.linhui.common.model.User;
import com.linhui.common.service.UserService;
import com.linhui.consumer.proxy.UserServiceProxy;
import com.linhui.rpc.proxy.ServiceProxy;
import com.linhui.rpc.proxy.ServiceProxyFactory;

import java.lang.reflect.Method;
import java.net.SocketTimeoutException;

/**
 * @author: 临晖
 * @since: 2024-05-10
 */
public class EasyConsumerExample {
    public static void main(String[] args) {
        //消费服务
        //rpc的作用，调用其它项目中的方法就想调用本地方法一下方便
        //降低了开发成本，使用方便
        //获取UserService的实现类对象
        //UserService userService = new UserServiceProxy();
        //User user = new User();
        //user.setName("tom");


        //最终结果，使用  userService.getUser();
        //是不是很方便！！！！！！！！！
        //User resUser = userService.getUser(user);
        //try {
        //    Method method = UserService.class.getMethod("getUser", User.class);
        //    User resUser = null;
        //    try {
        //        resUser = (User) new ServiceProxy().invoke(null, method, new Object[]{user});
        //    } catch (Throwable e) {
        //        throw new RuntimeException(e);
        //    }
        //    if (resUser != null) {
        //        System.out.println(resUser);
        //    } else {
        //        System.out.println("user为空");
        //    }
        //} catch (Exception e) {
        //    throw new RuntimeException(e);
        //}

        //v2
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("tom");
        userService.getUser(user);

    }
}
